/**
*  Copyright 2009-2014 by WWW.KNET.CN  All rights reserved.
*/
package com.domain.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.domain.model.CloudWebMessage;
import com.domain.model.Page;
import com.domain.service.CloudWebMessageService;

/**
 * TODO()
 * @author liujie
 * @date 2015年4月17日 下午1:28:38
 * 
 */
@Controller
@RequestMapping("/message")
public class MessageController  extends SuperController{
	private static final Logger logger = LoggerFactory.getLogger(MessageController.class);
   @Resource
   private CloudWebMessageService cloudWebMessageService;
   @RequestMapping("/list/{type}.html")
    public String msgList(HttpServletRequest request,ModelMap model,@PathVariable String type,String porCode,
    		Page page,HttpServletResponse response){
	   Map<String, Object> paramMap = new HashMap<String, Object>();
	   CloudWebMessage webMessage = new CloudWebMessage();
		webMessage.setPorCode(porCode);
		webMessage.setIfDelete(0l);
		paramMap.put(webMessage.key, webMessage);
		paramMap.put(PAGE_NAME, page.getPage());
		paramMap.put(PAGESIZE_NAME,page.getPageSize());
		paramMap.put("orderBy", "mes_status desc,mes_when desc");
		List<CloudWebMessage> msgList=cloudWebMessageService.getListPage(paramMap);
		Long total = cloudWebMessageService.getRows(paramMap);
		Page page2 = new Page(page.getPage(),page.getPageSize(), Integer.parseInt(total + ""));
		model.addAttribute("page", page2);
		model.addAttribute("list", msgList);
		model.addAttribute("porCode",porCode);
       	return String.format("message/%sList",type);
    }
    
   @RequestMapping("/msgShowDetail/{id}.html")
	public String msgShowDetail(HttpServletRequest request,@PathVariable Long id,HttpServletResponse response,ModelMap model) {
	   CloudWebMessage msg=cloudWebMessageService.get(id);
	   model.addAttribute("detail", msg);
	   model.addAttribute("porCode",msg.getPorCode());
	   logger.info("------------------------message detail id:{}",id);
	    return "message/msgDetail";
	}
   @RequestMapping(value="/textDetail.html")
   public String companyDetail(HttpServletRequest request, String porCode,HttpServletResponse response,ModelMap model){
	   Map<String, Object> paramMap = new HashMap<String, Object>();
	   CloudWebMessage webMessage = new CloudWebMessage();
		webMessage.setPorCode(porCode);
		webMessage.setIfDelete(0l);
		paramMap.put(webMessage.key, webMessage);
		paramMap.put(PAGE_NAME, 1);
		paramMap.put(PAGESIZE_NAME,1);
		paramMap.put("orderBy", "mes_status desc,mes_when desc");
		List<CloudWebMessage> msgList=cloudWebMessageService.getListPage(paramMap);
		if (null != msgList && msgList.size()>0) {
			CloudWebMessage msg=msgList.get(0);
			model.addAttribute("detail", msg);	
			logger.info("------------------------公司简介信息查看 detail id:{}",msg.getId());
		}
		model.addAttribute("porCode",porCode);
		
	   return "public/textDetail";
   }
	
}
